<?php

namespace api\Http\Controllers;

use Catch\Exceptions\FailedException;
use Illuminate\Routing\Controller as BaseController;
abstract class Controller  extends BaseController
{
    protected function getLoginUser(?string $guard = null, ?string $field = null): mixed
    {

        try {
            if (!is_null(request()->userInfo)) {
                return  request()->userInfo;
            }else{
                return '';
            }


        } catch (\Exception|\Throwable $e) {
            throw new FailedException('登录失效, 请重新登录',  400);
        }
    }

    /**
     */
    protected function getLoginUserId($guard = null): mixed
    {

        try {
            if (!is_null(request()->userId)) {
                return  request()->userId;
            }else{
                return '';
            }


        } catch (\Exception|\Throwable $e) {
            throw new FailedException('登录失效, 请重新登录',  400);
        }
    }
}
